﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Exhibition.Dao.ViewModel;
using AutoMapper;
namespace Exhibition.Dao
{

    public class BoothClassDao
    {


        public BoothClassDao()
        {

            Mapper.CreateMap<E_BoothClass, BoothClassModel>();
        }
        public List<E_BoothClass> GetList(int startIndex, int maxRow, out int recordcount)
        {


            using (ExhibitionEntities edm = new ExhibitionEntities())
            {

                recordcount = edm.E_BoothClass.Count();

                return edm.E_BoothClass.OrderByDescending(s => s.Id).Skip(startIndex).Take(maxRow).ToList();

            }

        }


        public BoothClassModel GetOneById(int id)
        {


            using (ExhibitionEntities edm = new ExhibitionEntities())
            {

                var query = edm.E_BoothClass.FirstOrDefault(s => s.Id == id);
                return Mapper.Map<E_BoothClass, BoothClassModel>(query);
            }

        }


        public int Save(BoothClassModel obj)
        {


            using (ExhibitionEntities edm = new ExhibitionEntities())
            {

                var query = edm.E_BoothClass.FirstOrDefault(s => s.Id == obj.Id);

                if (query == null)
                {


                    query = new E_BoothClass();

                    edm.AddToE_BoothClass(query);

                }


                query.ClassType = obj.ClassType;

                query.Uint = obj.Uint;

                query.Price = obj.Price;
                query.SiteID = obj.SiteID;
                query.FloorID = obj.FloorID;
                query.CreateUserId = obj.CreateUserId;
                edm.SaveChanges();

                return query.Id;


            }

        }

        public List<BoothClassModel> GetBoothClassList(int siteid)
        {
            using (ExhibitionEntities edm = new ExhibitionEntities())
            {
                var query = edm.E_BoothClass.Where(s=>s.SiteID==siteid);
                return Mapper.Map<List<E_BoothClass>, List<BoothClassModel>>(query.ToList());
            }
        }


        public List<BoothClassModel> GetBoothClassList(int preid, int siteid)
        {
            using (ExhibitionEntities edm = new ExhibitionEntities())
            {
                return null;
                //var query = edm.E_BoothClass.Where(s => s.SiteID == siteid&&s.FloorID);
                //return Mapper.Map<List<E_BoothClass>, List<BoothClassModel>>(query.ToList());
            }
        }


        public int DelById(int id)
        {


            using (ExhibitionEntities edm = new ExhibitionEntities())
            {

                var query = edm.E_BoothClass.FirstOrDefault(s => s.Id == id);

                if (query != null)
                {


                    edm.DeleteObject(query);


                }


                return edm.SaveChanges();


            }

        }


    }

}

